<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/static/img/logo/favicon.ico" />
    <link rel="stylesheet" href="/static/assets/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/static/css/footer.css">
    <link rel="stylesheet" href="/static/css/header.css">
    <title>论坛</title>

</head>

<body class="home">
    {% include 'header.html' %}

    <div style="width: 100%;height: 60%;">
        <div style="width: 400px; height: 100px; margin: 0 auto;margin-top: 15%;margin-bottom: 20%;">
            <div class="span4">
                <div class="input-prepend mt-2" style="width: 600px;">
                    <span class="add-on">更改账号：</span><input style="width: 300px" class="span2" id="uid" size="16"
                        type="text" name="username" disabled="disabled" placeholder="{{ user.username }}">
                </div>
                <div class="input-prepend mt-2" >
                    <span class="add-on">头&#12288;&#12288;像：</span><input style="width: 300px" class="span2" id="avatar" size="16"
                        type="file" name="avatar" placeholder="{{ user.faculty }}">
                </div>
                <div class="input-prepend mt-2" >
                    <span class="add-on">学&#12288;&#12288;院：</span><input style="width: 300px" class="span2" id="faculty" size="16"
                        type="text" name="faculty" placeholder="{{ user.faculty }}">
                </div>
                <div class="input-prepend mt-2">
                    <span class="add-on">专&#12288;&#12288;业：</span><input style="width: 300px" class="span2" id="major" size="16"
                        type="text" name="major" placeholder="{{ user.major }}">
                </div>
                <div class="input-prepend mt-2">
                    <span class="add-on">性&#12288;&#12288;别：</span><input style="width: 300px" class="span2" id="sex" size="16"
                        type="text" name="sex" placeholder="{{ user.sex }}">
                </div>
                <div class="input-prepend mt-2">
                    <span class="add-on">年&#12288;&#12288;龄：</span><input style="width: 300px" class="span2" id="age" size="16"
                        type="text" name="age" placeholder="{{ user.age }}">
                </div>
                <div class="input-prepend mt-2">
                    <span class="add-on">个人简介：</span><input style="width: 300px" class="span2" id="profile" size="16"
                        type="text" name="profile" placeholder="{{ user.profile }}">
                </div>
                <div class="input-prepend mt-2">
                    <span class="add-on">确认密码：</span><input style="width: 300px" class="span2" id="pwd" size="16"
                        type="password" name="pwd" placeholder="输入密码">
                </div>
                <div class="p-3 ms-5" style="width: 300px;">
                    <button id="login-button" style="margin-right: 20px;margin-left: 20px;" class="btn btn-primary"
                        type="submit">提交
                    </button>
                    <button id="cancel-button" style="margin-right: 20px;margin-left: 80px;"
                        class="btn btn-primary btn-inverse" type="submit">取消
                    </button>
                </div>
            </div>
        </div>
    </div>

    {% include 'footer.html' %}

    <script src="/static/assets/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
    <script src="/static/assets/plugins/jquery/jquery.min.js"></script>
    <script>
        $(document).ready(function () {
            $('#login-button').click(function () {
                var faculty = $('#faculty').val();
                var major = $('#major').val();
                var sex = $('#sex').val();
                var age = $('#age').val();
                var profile = $('#profile').val();
                var pwd = $('#pwd').val();
                var files = $('input[name="avatar"]').prop('files');
                var fdata = new FormData();
                fdata.append('avatar', files[0]);
                fdata.append('faculty', faculty);
                fdata.append('major', major);
                fdata.append('sex', sex);
                fdata.append('age', age);
                fdata.append('profile', profile,);
                fdata.append('pwd', pwd);

                $.ajax({
                    url: window.location.href,
                    type: "POST",
                    data: fdata,
                    cache: false,
                    processData: false,
                    contentType: false,

                    beforeSend: function (xhr, settings) {
                        xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");    
                    },
                    success: function (data) {
                        if (!data.status) alert(data.msg);
                        else window.location.href = "/user-info/";
                    }
                });
            });

            $('#cancel-button').click(function () {
                window.location.href = "/home";
            });
        });
    </script>
</body>

</html>